<template>
  <el-dialog
    :title="title"
    :visible.sync="dialogFormVisible"
    width="700px"
    @close="close"
  >
    <el-form ref="form" label-width="80px" :model="form" :rules="rules" label-position="right">
      <el-form-item label="分类名称" prop="class_name">
        <el-input v-model.trim="form.class_name" />
      </el-form-item>
    </el-form>
    <template #footer>
      <el-button @click="close">取 消</el-button>
      <el-button type="primary" @click="save">确 定</el-button>
    </template>
  </el-dialog>
</template>

<script>

  import {doEdit  } from '@/api/manage/adClass'

  export default {
    name: 'adClassManagementEdit',
    data() {
      return {
        form: {
        },
        rules: {
          class_name: [
            { required: true, trigger: 'blur', message: '请填写分类名称' },
          ],
        },
        title: '',
        dialogFormVisible: false,
        columnList:[],
        infoList:[],
        statusMap:[
          {
            status:0,
            text:'禁用'
          },
          {
            status:1,
            text:'启用'
          }
        ],
        targetMap:[
          {
            target:'_blank',
            text:'新页面打开'
          },
          {
            target:'_self',
            text:'当前页打开'
          }
        ],
        sonMap:[
          {
            son:1,
            text:'栏目列表'
          },
          {
            son:2,
            text:'栏目分类'
          }
        ],
        typeMap:[
          {
            type:1,
            text:'栏目'
          },
          {
            type:2,
            text:'单页'
          },
          {
            type:3,
            text:'固定连接'
          }
        ]

      }
    },
    created(){
      // this.getFilter()
    },
    methods: {
      forceUpdate(){
        this.$forceUpdate()
      },
      getFilter(){
        getFilter().then(response=>{
          this.columnList=response.data.columnList
          this.infoList=response.data.infoList
        })
      },
      showEdit(row) {
        if (!row) {
          this.title = '添加'
        } else {
          this.title = '编辑'
          this.form = Object.assign({}, row)
        }
        this.dialogFormVisible = true
      },
      close() {
        this.$refs['form'].resetFields()
        this.form = this.$options.data().form
        this.dialogFormVisible = false
      },
      save() {
        this.$refs['form'].validate(async (valid) => {
          if (valid) {
            const { msg } = await doEdit(this.form)
            this.$baseMessage(msg, 'success', 'vab-hey-message-success')
            this.$emit('fetch-data')
            this.close()
          }
        })
      },
    },
  }
</script>
